//
//  MJChooseImageView.m
//  MJ
//
//  Created by qiaoBu on 2017/12/8.
//  Copyright © 2017年 lina. All rights reserved.
//

#import "MJChooseImageView.h"

@implementation MJChooseImageView

- (instancetype)initWithFrame:(CGRect)frame{
    
    if (self = [super initWithFrame:frame])
    {
        self.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.3];
        [self commonInit];
    }
    return self;
}
- (void)commonInit{
 
    
    UIView *whiteView = [[UIView alloc] init];
    [self addSubview:whiteView];
    whiteView.backgroundColor = [UIColor whiteColor];
    [whiteView mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.left.right.bottom.mas_equalTo(self);
        make.height.mas_equalTo(140);
    }];
    
    UIButton *cancelBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [self addSubview:cancelBtn];
    [cancelBtn mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.left.right.bottom.mas_equalTo(whiteView);
        make.height.mas_equalTo(45);
    }];
    [cancelBtn setTitle:@"取消" forState:UIControlStateNormal];
    [cancelBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [cancelBtn addTarget:self action:@selector(cancelBtnClick:) forControlEvents:UIControlEventTouchUpInside];
    cancelBtn.titleLabel.font = [UIFont systemFontOfSize:16.f];
    
    UIButton *takePicBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [self addSubview:takePicBtn];
    [takePicBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.right.height.mas_equalTo(cancelBtn);
        make.bottom.mas_equalTo(cancelBtn.mas_top).offset(-5);
    }];
    [takePicBtn setTitle:@"从手机相册选择" forState:UIControlStateNormal];
    [takePicBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [takePicBtn addTarget:self action:@selector(takePicsBtnClick:) forControlEvents:UIControlEventTouchUpInside];
    takePicBtn.titleLabel.font = [UIFont systemFontOfSize:16.f];
    takePicBtn.tag = 11;
    
    UIView *grayView = [[UIView alloc] init];
    [self addSubview:grayView];
    [grayView mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.left.right.mas_equalTo(whiteView);
        make.height.mas_equalTo(5);
        make.bottom.mas_equalTo(cancelBtn.mas_top);
    }];
    grayView.backgroundColor = RGBColor(242,242,242);
    
    UIButton *photoBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [self addSubview:photoBtn];
    [photoBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.right.height.mas_equalTo(cancelBtn);
        make.bottom.mas_equalTo(takePicBtn.mas_top);
       
    }];
    [photoBtn setTitle:@"拍照" forState:UIControlStateNormal];
    [photoBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [photoBtn addTarget:self action:@selector(chooseImageBtnClick:) forControlEvents:UIControlEventTouchUpInside];
    photoBtn.titleLabel.font = [UIFont systemFontOfSize:16.f];
    photoBtn.tag = 10;
    
    UIView *topLine = [[UIView alloc] init];
    [whiteView addSubview:topLine];
    [topLine mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.right.bottom.mas_equalTo(photoBtn);
        make.height.mas_equalTo(0.5);
    }];
    topLine.backgroundColor = RGBColor(229,229,229);
    
   
}
- (void)cancelBtnClick:(UIButton *)button{
    
    self.hidden = YES;
}
- (void)chooseImageBtnClick:(UIButton *)button{
    
     self.hidden = YES;
    if (self.chooseImageBlock)
    {
        self.chooseImageBlock(button.tag);
    }
}
- (void)takePicsBtnClick:(UIButton *)button{
    
     self.hidden = YES;
    if (self.chooseImageBlock)
    {
        self.chooseImageBlock(button.tag);
    }
}

@end
